Allow Natl Topo to allow override of datums for benefit of users in HI.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 15 Sep 2005 01:53:04 +0000 (01:53 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 15 Sep 2005 01:53:04 +0000 (01:53 +0000)
gpsbabel/README
gpsbabel/jeeps/gpsmath.c
gpsbabel/jeeps/gpsmath.h
gpsbabel/tpg.c

index c6031e74170498ea01db5297941b116098c3bbee..cba352a24090b16db708fded7b3b65105e1f42c2 100644 (file)
@@ -470,6 +470,12 @@ THE FORMATS
        National Geographic Topo! Waypoint Format.  This filter 
        reads and writes .TPG files created by various editions of NG Topo! 
        This filter will *not* work with the newer combined .TPO files.  
+
+        The option 'datum="datum name"' can be used to override the
+        default of NAD27 ("N. America 1927 mean") which is correct
+        for the continental U.S. Points in Hawaii should use "Old
+        Hawaiian_mean"
+
        Contributed by Alex Mottram.
 
     HOLUX
index e3a9284a77cd4acc6f0e6f0171eba3d51f7790d0..ac412f19697edf40a19896ff623f3a12f6a6d976 100644 (file)
@@ -1797,3 +1797,16 @@ int32 GPS_Math_UTM_EN_To_WGS84(double *lat, double *lon, double E,
 
     return 1;
 }
+
+int32 GPS_Lookup_Datum_Index(const char *n)
+{
+       GPS_PDatum dp;
+
+       for (dp = GPS_Datum; dp->name; dp++) {
+               if (0 == case_ignore_strcmp(dp->name, n)) {
+                       return dp - GPS_Datum;
+               }
+       }
+
+       return -1;
+}
index 4e2249f08e4ff6aef800c02b592bbb5d259c3e0f..e308b8514f123c0f0b802b83a59043ba4de4547b 100644 (file)
@@ -116,6 +116,8 @@ int32 GPS_Math_UTM_EN_To_WGS84(double *lat, double *lon, double E,
 int32 GPS_Math_UTM_EN_To_NAD83(double *lat, double *lon, double E,
                               double N, int32 zone, char zc);
 
+int32 GPS_Lookup_Datum_Index(const char *n);
+
 #endif
 
 #ifdef __cplusplus
index 81b80daf0181de865e3292836aa16cca17193705..1c2022d428fdf43769cf4c15f7625ab3b849f6fb 100644 (file)
 static FILE *tpg_file_in;
 static FILE *tpg_file_out;
 static void *mkshort_handle;
+static char *tpg_datum_opt;
+static int tpg_datum_idx;
 
 static unsigned int waypt_out_count;
 
+static
+arglist_t tpg_args[] = {
+       {"datum", &tpg_datum_opt, "Datum (default=NAD27)", "N. America 1927 mean", ARGTYPE_STRING },
+       {0, 0, 0, 0, 0}
+};
+
 static int
 tpg_fread(void *buff, size_t size, size_t members, FILE * fp) 
 {
@@ -85,9 +93,19 @@ valid_tpg_header(char * header, int len)
     return memcmp(header_bytes, header, len);
 }
 
+static void
+tpg_common_init(void)
+{
+       tpg_datum_idx = GPS_Lookup_Datum_Index(tpg_datum_opt);
+       if (tpg_datum_idx < 0) {
+               fatal(MYNAME ": Datum '%s' is not recognized.\n", tpg_datum_opt);
+       }
+}
+
 static void
 tpg_rd_init(const char *fname)
 {
+       tpg_common_init();
        tpg_file_in = xfopen(fname, "rb", MYNAME);
 }
 
@@ -100,6 +118,7 @@ tpg_rd_deinit(void)
 static void
 tpg_wr_init(const char *fname)
 {
+       tpg_common_init();
        tpg_file_out = xfopen(fname, "wb", MYNAME);
        mkshort_handle = mkshort_new_handle();
        waypt_out_count = 0;
@@ -172,7 +191,7 @@ tpg_read(void)
                 &wpt_tmp->latitude,
                 &wpt_tmp->longitude,
                 &amt,
-                78);
+                tpg_datum_idx);
 
             wpt_tmp->altitude = elev;
             
@@ -255,7 +274,7 @@ tpg_waypt_pr(const waypoint *wpt)
                 &lat,
                 &lon,
                 &amt,
-                78);
+                tpg_datum_idx);
         
 
         /* swap the sign back *after* the datum conversion */
@@ -365,6 +384,6 @@ ff_vecs_t tpg_vecs = {
        tpg_read,
        tpg_write,
        NULL,
-       NULL,
+       tpg_args,
        CET_CHARSET_ASCII, 0    /* CET-REVIEW */
 };